package com.chengjue.controller;

import com.chengjue.service.RequireService;
import com.chengjue.common.Const;
import com.chengjue.common.ServerResponse;
import com.chengjue.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/require")
public class ReuqireController {
    @Autowired
    RequireService requireService;

    @RequestMapping(value = "get/data", method = RequestMethod.GET)
    public ServerResponse<String> getData(HttpSession session){
        UserModel userModel = (UserModel) session.getAttribute(Const.CURRENT_USER);
        if(userModel == null){
            return ServerResponse.createByErrorMessage("用户未登录");
        }

        return requireService.getData(userModel.getId());
    }


    @RequestMapping(value = "list", method = RequestMethod.GET)
    public ServerResponse getList(@RequestParam(defaultValue = "1",value = "pageNum") int pageNum, @RequestParam(defaultValue = "20",value = "pageSize")int pageSize){
        return requireService.getList(pageNum,pageSize);
    }




}
